package com.gjs.freechat.server.component;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.gjs.freechat.server.component.bean.UserInfo;

@Component
public class UsersPoolManage {
	private List<UserInfo> usersPool;
	
	public UsersPoolManage() {
		usersPool = Collections.synchronizedList(new LinkedList<UserInfo>());
	}
	
	public void add(UserInfo userInfo) {
		usersPool.add(userInfo);
	}
	
	public void remove(UserInfo userInfo) {
		usersPool.remove(userInfo);
	}
	
	public UserInfo get(String userId) {
		for (UserInfo userInfo : usersPool) {
			if (userInfo.getId().equals(userId)) {
				return userInfo;
			}
		}
		return null;
	}
	
	public int getOnlineUsersCount() {
		return usersPool.size();
	}
}
